// pages/huiyiRicheng/huiyiRicheng.js
var app = getApp();
Page({
  data: {
    winHeight: "",//窗口高度
    currentTab: 0, //预设当前项的值
    scrollLeft: 0, //tab标题的滚动条位置
    expertList: [{ //假数据
    }],//===========================
    navindex: 1,//选择的 导航  1：我发起的   2：我参与的
    joinList: [],//我参与的 数据列表
    myList: [],
    // mylist: [  //status    1:未取消    2：已取消，可删除
    show: "",
  },
  clickSaoyiSao: function () {
    var that = this;
    wx.scanCode({
      success: (res) => {
        console.log(res);
        that.qiandao(res.result);
      },
      fail: (res) => {
        wx.showToast({
          title: '失败',
          icon: 'success',
          duration: 2000
        })
      },
      complete: (res) => {
      }
    })
  },
  qiandao: function (res) {
    console.log(res);
    wx.request({
      header: app.header(),
      url: app.globalData.url + '/signIn/meeting/'+res,
      data: {},
      method: 'POST',
      success: function (res) {
        if (res.data.status == "success") {
          wx.showToast({
            title: '签到成功',
            icon: 'success',
            duration: 2000
          })
        }
      }
    })
  },
  //取消日程
  cancelRicheng: function (e) {
    var _this = this;
    var mylist = this.data.myList;
    var index = e.currentTarget.dataset.index;
    wx.showModal({
      title: '提示',
      content: '确定要取消会议日程？',
      showCancel: true,//是否显示取消按钮
      cancelText: "否",//默认是“取消”
      cancelColor: 'skyblue',//取消文字的颜色
      confirmText: "是",//默认是“确定”
      confirmColor: 'skyblue',//确定文字的颜色
      success: function (res) {
        if (res.cancel) {
          //点击取消,默认隐藏弹框
        } else {
          var metting = mylist[index];
          _this.cancelHuiYi(metting.id, index);

        }
      },
      fail: function (res) { },//接口调用失败的回调函数
      complete: function (res) { },//接口调用结束的回调函数（调用成功、失败都会执行）
    })
  },
  //取消日程
  cancelHuiYi: function (id, index) {
    var _this = this;
    var mylist = _this.data.myList;
    var header = app.header();
    wx.request({
      url: app.globalData.url + '/meeting/updateStatus',//新增会议接口
      method: 'POST',
      header: { "Content-Type": "application/x-www-form-urlencoded" ,
        token: header['token']},
      data: { id: id, status: 2 },
      success: function (res) {
        if (res.data.success == true) {
          mylist.splice(index, 1);
          _this.setData({
            myList: mylist
          })
        }
      }
    })
  },
  //删除日程
  delRicheng: function (e) {
    var _this = this;
    var mylist = _this.data.myList;
    var index = e.currentTarget.dataset.index;
    wx.showModal({
      title: '删除',
      content: '确定要删除会议日程？',
      showCancel: true,//是否显示取消按钮
      cancelText: "否",//默认是“取消”
      cancelColor: 'skyblue',//取消文字的颜色
      confirmText: "是",//默认是“确定”
      confirmColor: 'skyblue',//确定文字的颜色
      success: function (res) {
        if (res.cancel) {
          //点击取消,默认隐藏弹框
        } else {
          var metting = mylist[index];
          _this.delHuiYi(metting, index);

        }
      },
      fail: function (res) { },//接口调用失败的回调函数
      complete: function (res) { },//接口调用结束的回调函数（调用成功、失败都会执行）
    })

  },
  //编辑日程（跳转页面）
  editRicheng: function (e) {
    var _this = this;
    var mylist = _this.data.myList;
    var index = e.currentTarget.dataset.index;
    wx.navigateTo({
      url: '../meetingEdit/meetingEdit?id=' + mylist[index].id
    })
  },
  //删除会议
  delHuiYi(metting, index) {
    var _this = this;
    var mylist = _this.data.myList;
    var header = app.header();
    wx.request({
      url: app.globalData.url + '/meeting/del',//新增会议接口
      method: 'POST',
      header: { "Content-Type": "application/x-www-form-urlencoded" ,
        token: header['token']},
      data: { id: metting.id },
      success: function (res) {
        if (res.data.success == true) {
          mylist.splice(index, 1);
          _this.setData({
            myList: mylist
          })
        }
      }
    })
  },
  //跳转会议详情
  goMeetDetail: function (e) {
    var index = e.currentTarget.dataset.index;
    var _this = this;
    var mylist = _this.data.myList;
    wx.navigateTo({
      url: '../meetingDetail/meetingDetail?id=' + mylist[index].id
    })
  },
  //==切换导航==
  changenav: function (e) {
    var index = e.currentTarget.dataset.index;
    this.setData({
      navindex: index
    })
  },
  // 滚动切换标签样式
  switchTab: function (e) {
    this.setData({
      currentTab: e.detail.current
    });
    this.checkCor();
  },
  // 点击标题切换当前页时改变样式
  swichNav: function (e) {
    var cur = e.target.dataset.current;
    if (this.data.currentTaB == cur) { return false; }
    else {
      this.setData({
        currentTab: cur
      })
    }
  },
  //判断当前滚动超过一屏时，设置tab标题滚动条。
  checkCor: function () {
    if (this.data.currentTab > 2) {
      this.setData({
        scrollLeft: 300
      })
    } else {
      this.setData({
        scrollLeft: 0
      })
    }
  },

	/**
	 * 生命周期函数--监听页面显示
	 */
  onShow: function () {

  },

	/**
	 * 生命周期函数--监听页面隐藏
	 */
  onHide: function () {

  },

	/**
	 * 页面上拉触底事件的处理函数
	 */
  onReachBottom: function () {

  },
  onLoad: function () {
    var that = this;
    //  高度自适应
    wx.getSystemInfo({
      success: function (res) {
        var clientHeight = res.windowHeight,
          clientWidth = res.windowWidth,
          rpxR = 750 / clientWidth;
        var calc = clientHeight * rpxR - 180;
        console.log(calc)
        that.setData({
          winHeight: calc
        });
      }
    });
    wx.request({
      header: app.header(),
      url: app.globalData.url + '/meeting/listMeeting',//新增会议接口
      method: 'GET',
      success: function (res) {
        if (res.data.status == 'success') {
          that.setData({
            myList: res.data.result.addList,//我参与的 数据列表
            joinList: res.data.result.joinList,
          })
        }
      }
    })
  },
  footerTap: app.footerTap
})